package com.example.accessibilityhelper

import android.accessibilityservice.AccessibilityService
import android.view.accessibility.AccessibilityEvent

abstract class Step {

    private lateinit var task: Task

    @TaskState
    private var state = TaskState.STATE_INIT

    private val isFinished :Boolean get() = state == TaskState.STATE_FINISHED

    fun attach(task: Task) {
        this.task = task
    }

    open fun onStart(){

    }

    abstract fun match(service: AccessibilityService, event: AccessibilityEvent): Boolean

    abstract fun execute(service: AccessibilityService, event: AccessibilityEvent)

    fun finish() {
        this.task.finish(this)
        state = TaskState.STATE_FINISHED
    }
}